// JavaScript Document

$(function(){
	
	//
	$(document.body).on('click','[data-type="barcode_candidate"] > .delete',function(){
		 var container=$(this).parents('[data-type="barcode_candidate"]:eq(0)'); 																   
		 var orderno=container.data('orderno')||'';
		 var barcode=container.data('barcode')||'';
		 var id=container.attr('id');
		 try {
                        //删除条码
                        $.ajax({
                            type: 'POST',
                            url: '/deleteCodeDetail.asp',
                            data: {action:'scandataadd', newSn:orderno,Barcode:barcode },
                            dataType: 'json',
                            timeout: 30000,
                            success: function (data) {
								if (!data.ret_barcode.error_response) {   
									 listcode.splice(id, 1); 
									 UpdateBarCode();
								} else {
									alertify.alert(data.ret_barcode.error_response);
								} 
                            },
                            error: function (xhr, type) {
                                alertify.error('超时,或服务错误'); 
                            }
                        });
                    } catch (e) {
                        alert(e);
                    } 
					
    });	   
		   
		   
	//	   
    $(document.body).on('click','[data-type="customer-li"]',function(){
	   var mobile=$(this).data('mob')||'';
	   var name=unescape($(this).data('name')||'');
	   
	   alertify.confirm('是否选择:'+name, function(e) {
			if (e) {
                    $('#codelListArea').html('');  
                    ToCustomer_ID = mobile;
                    try {
                        //主录入,成功返回空值
                        $.ajax({
                            type: 'POST',
                            url: '/createFahuoDan.asp',
                            data: {action:'scandataadd', tousername:ToCustomer_ID },
                            dataType: 'json',
                            timeout: 30000,
                            success: function (data) {
								if (!data.ret_order.error_response) {   
									query = false;  
									$('#queryPlane').toggle(query);  
									$('#btnNewCode').html('<p>'+data.ret_order.orderno+'</p><p>'+name+'</p>').data('mobile',mobile);
									//$('#deleteBtn').html('删除');
									newSn=data.ret_order.orderno;
									brands=name;
								} else {
									alertify.alert(data.ret_order.error_response);
								} 
                            },
                            error: function (xhr, type) {
                                alertify.error('超时,或服务错误'); 
                            }
                        });
                    } catch (e) {
                        alert(e);
                    } 
                } else {
                    //不选择..
                }									 
		});
	})		   
		   
		   
});

function UpdateBarCode(){
        var render = template.compile(sourceHtml);
        var html = render({
            list: listcode
        });
		$('#code').val('');
		$('#CodeList').html(html);	
}